package com.ttl.bc.master.department;

import hibernate.util.HibernateUtil;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.hibernate.classic.Session;

import com.ttl.common.db.ADAO;
import com.ttl.common.user.department.ITTL_UserDepartment;

public class BCDepartmentDAO extends ADAO {

	@SuppressWarnings("unchecked")
	public List findAll() {
		List result = null;
		@SuppressWarnings("unused")
		ArrayList result2 = new ArrayList();
		Session session = null;

		try {
			SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
			session = sessionFactory.openSession();
			
			session.beginTransaction();
			
			Query q = session.createQuery("FROM BCDepartmentBean ORDER BY code");
			result = q.list();			
						
			session.getTransaction().commit();						
			
		}catch(Exception e) {			
			System.out.println(e.toString());
		}finally {
			session.close();
		}
		
 		
		
		return result;
	}

	public List<ITTL_UserDepartment> findAll_userInDept(String user) {
		List<ITTL_UserDepartment> list = null;
		
		Session session = null;
		try {
			SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
			session = sessionFactory.openSession();
			
			session.beginTransaction();
			
			Query q = session.createQuery("FROM ITTL_UserDepartment WHERE userName='"+user+"' ");
			list = q.list();			
						
			session.getTransaction().commit();						
			
		}catch(Exception e) {			
			System.out.println(e.toString());
		}finally {
			session.close();
		}		
		
		return list;
	}	
}
